package com.example.administrator.netdemo.network;

/**
 * Created by liukun on 16/3/10.
 */
public class ApiException extends RuntimeException {

    public static final int REQUEST_SUCCESS = 0;
    public static final int NETWORK_ERR = -1;
    public static final int REQUEST_CANCEL_ERR = -2;
    public static final int STATE_ERR = -3;
    public static final String ERR_MSG = "获取数据失败，请稍后再试~";

    public ApiException(int resultCode) {
        this(getApiExceptionMessage(resultCode));
    }

    public ApiException(String detailMessage) {
        super(detailMessage);
    }

    /**
     * 由于服务器传递过来的错误信息直接给用户看的话，用户未必能够理解
     * 需要根据错误码对错误信息进行一个转换，在显示给用户
     *
     * @param code
     * @return
     */
    public static String getApiExceptionMessage(int code) {
        String message = "";
        switch (code) {
            case NETWORK_ERR:
                message = "获取数据失败";
                break;
            default:
                message = "获取数据失败";
        }
        return message;
    }
}

